'use strict';

var entryFactory = require('../../../../factory/EntryFactory');
var is = require('bpmn-js/lib/util/ModelUtil').is;


/**
 * Create an entry to modify the name of an an element.
 *
 * @param  {djs.model.Base} element
 * @param  {Object} options
 * @param  {string} options.id the id of the entry
 * @param  {string} options.label the label of the entry
 *
 * @return {Array<Object>} return an array containing
 *                         the entry to modify the name
 */
module.exports = function(element, options, translate) {

  options = options || {};
  var id = options.id || 'name',
      label = options.label || translate('Name'),
      modelProperty = options.modelProperty || 'name';

  var nameEntry = entryFactory.textBox({
    id: id,
    label: label,
    modelProperty: modelProperty,
    validate: function (element, value) {
      // console.log('任务规则名称不能为空')
      var validation = {};
      if (is(element, 'bpmn:BusinessRuleTask')) {
        if (!value.name) {
          validation.name = '任务规则名称不能为空';
        }
      }
      return validation;
    }
  });

  return [ nameEntry ];

};
